package net.chrone.quickpayapi.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.alibaba.fastjson.JSON;

import net.chrone.quickpayapi.util.HttpClientHelper;
import net.chrone.quickpayapi.util.HttpResponse;
import net.chrone.quickpayapi.util.SignatureUtil;

public class NotifyController {
	
	@Test
	public void testSDKNotify(){
		Map<String,String> respMap = new HashMap<String, String>();
		respMap.put("mchntOrderNo","SJ2016093000003832");
		respMap.put("body","赤兔码-等级提升");
		respMap.put("paidTime","1472467014000");
		respMap.put("extra","");
		respMap.put("mchntId","0000002072");
		respMap.put("subject","赤兔码-等级提升");
		respMap.put("appid","0000005008");
		respMap.put("paySt","2");
		respMap.put("amount","8800");
		respMap.put("fee","132");
		respMap.put("orderNo","14752123334050001867");
		respMap.put("description","");
		respMap.put("orderDt","20160930");
		respMap.put("signature", "2520fae6349d90d60eee20bc870aeb7c");
		try{
			HttpResponse response = HttpClientHelper.doHttp("http://paycode.buybal.com/fvp-qp-business/resultNotice.html", HttpClientHelper.POST, "utf-8", JSON.toJSONString(respMap), "60000");
			System.out.println(response.getRspStr());
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testQuickNotify(){
		Map<String,String> respMap = new HashMap<String, String>();
		respMap.put("account","15101143783");
		respMap.put("amount","100");
		respMap.put("body","");
		respMap.put("description","");
		respMap.put("extra","");
		respMap.put("fee","0");
		respMap.put("orderDt","20160829");
		respMap.put("orderNo","14772771677630000034");
		respMap.put("orgId","000005");
		respMap.put("orgOrderNo","2016102410460610");
		respMap.put("paySt","2");
		respMap.put("respCode","200");
		respMap.put("subject","");
		respMap.put("signature", SignatureUtil.signResp(respMap));
		try{
			HttpResponse response = HttpClientHelper.doHttp("http://106.38.100.170:18082/qen/notify", HttpClientHelper.POST, "utf-8", JSON.toJSONString(respMap), "60000");
			System.out.println(response.getRspStr());
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	@Test
	public void testQuickApiNotify(){
		List<String[]> params = new ArrayList<String[]>();
		params.add(new String[]{"respCode","000000"});
		params.add(new String[]{"respInfo","交易成功"});
		params.add(new String[]{"orderId","D0100115072003710479"});
		try{
			String postStr = HttpClientHelper.getNvPairs(params, "utf-8");
			HttpResponse response = HttpClientHelper.doHttp("http://quick.chrone.net/quick-pay-api/v1.0/notify/kubei", HttpClientHelper.POST, "utf-8", postStr, "60000");
			System.out.println(response.getRspStr());
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	@Test
	public void testQuickTsNotify(){
		Map<String,String> respMap = new HashMap<String, String>();
		respMap.put("fee","6");
		respMap.put("mac","39354134");
		respMap.put("orgSendSeqId","14745585743413594");
		respMap.put("organizationId","");
		respMap.put("payDesc","支付成功");
		respMap.put("payResult","00");
		respMap.put("t0RespCode","00");
		respMap.put("t0RespDesc","承兑或交易成功");
		respMap.put("transAmt","1000");
		try{
			System.out.println(JSON.toJSON(respMap));
			HttpResponse response = HttpClientHelper.doHttp("http://quickapi.chrone.net/quick-pay-api/v1.0/notify/tengshi", HttpClientHelper.POST, "utf-8", "data="+JSON.toJSONString(respMap), "60000");
			System.out.println(response.getRspStr());
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
}
